﻿using System;
using System.Collections.Generic;
using System.Text;
using PostSharp.Aspects.Dependencies;

namespace Arcana.Contract.Method.Returns.Is.Equal
{
    /// <summary>
    /// Represents a contract that adheres to <b>Method returns is equal to</b> semantic.
    /// </summary>
    [Serializable]
    [ProvideAspectRole(Roles.Contract)]
    [ProvideAspectRole(Roles.Method)]
    [ProvideAspectRole(Roles.ReturnValue)]
    [ProvideAspectRole(Roles.Conditional)]
    [AspectRoleDependency(AspectDependencyAction.Commute, Roles.Conditional)]
    public sealed class ToAttribute : ComparingContractBase
    {
        private object _value;

        /// <summary>
        /// Initializes a new instance of <b>Method.Returns.Is.Equal.ToAttribute</b>.
        /// </summary>
        /// <param name="value">The value which method return value should be equal to</param>
        public ToAttribute(object value)
        {
            _value = value;
        }

        /// <summary>
        /// Performs validation on the retunr value.
        /// </summary>
        /// <param name="value">The return value that should be validated.</param>
        /// <returns><b>true</b> if <i>value</i> is validated, otherwise <b>false</b>.</returns>
        protected override bool ValidateValue(object value)
        {
            return Comparer.Compare(value, _value) == 0;
        }
    }
}
